<template>
  <div class="enterprise-test">
    <h2>企业信息页面测试</h2>
    <div class="test-links">
      <h3>测试链接：</h3>
      <ul>
        <li><a href="/account/companyInfo" target="_blank">企业信息页面</a></li>
      </ul>
    </div>
    
    <div class="api-test">
      <h3>API接口测试：</h3>
      <div class="test-section">
        <h4>测试获取企业信息API：</h4>
        <button @click="testGetEnterpriseInfo" :disabled="loading">测试获取企业信息</button>
        <div v-if="enterpriseData" class="result">
          <h5>企业信息数据：</h5>
          <pre>{{ JSON.stringify(enterpriseData, null, 2) }}</pre>
        </div>
      </div>
      
      <div class="test-section">
        <h4>测试获取用户基本信息API：</h4>
        <button @click="testGetUserInfo" :disabled="loading">测试获取用户信息</button>
        <div v-if="userData" class="result">
          <h5>用户信息数据：</h5>
          <pre>{{ JSON.stringify(userData, null, 2) }}</pre>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getAccoutEnterPriseInfo, getAccoutBaseInfo } from '@/api/tenant'
import Cookies from 'js-cookie'

export default {
  name: 'EnterpriseTest',
  data() {
    return {
      loading: false,
      enterpriseData: null,
      userData: null
    }
  },
  methods: {
    async testGetEnterpriseInfo() {
      this.loading = true
      try {
        // 模拟企业ID
        const tenantId = '1'
        const res = await getAccoutEnterPriseInfo(tenantId)
        this.enterpriseData = res
        console.log('企业信息获取成功:', res)
      } catch (error) {
        console.error('获取企业信息失败:', error)
        this.$message.error('获取企业信息失败: ' + error.message)
      } finally {
        this.loading = false
      }
    },
    
    async testGetUserInfo() {
      this.loading = true
      try {
        // 模拟账户ID
        const accountId = '1'
        const res = await getAccoutBaseInfo(accountId)
        this.userData = res
        console.log('用户信息获取成功:', res)
      } catch (error) {
        console.error('获取用户信息失败:', error)
        this.$message.error('获取用户信息失败: ' + error.message)
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped>
.enterprise-test {
  padding: 20px;
}

.test-links ul {
  list-style: none;
  padding: 0;
}

.test-links li {
  margin: 10px 0;
}

.test-links a {
  color: #409eff;
  text-decoration: none;
  font-family: monospace;
}

.test-links a:hover {
  text-decoration: underline;
}

.api-test {
  margin-top: 30px;
  padding: 20px;
  background: #f5f5f5;
  border-radius: 4px;
}

.test-section {
  margin: 20px 0;
  padding: 15px;
  background: white;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
}

.test-section button {
  background: #409eff;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 10px;
}

.test-section button:disabled {
  background: #c0c4cc;
  cursor: not-allowed;
}

.result {
  margin-top: 15px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 4px;
  border: 1px solid #e9ecef;
}

.result pre {
  margin: 0;
  font-size: 12px;
  color: #333;
  white-space: pre-wrap;
  word-wrap: break-word;
}
</style>
